package main

import (
	"context"
	"github.com/redis/go-redis/v9"
)

var redisClient *redis.Client

func initRedis() error {
	cfg := GlobalConfig.Redis

	redisClient = redis.NewClient(&redis.Options{
		Addr:     cfg.GetAddr(),
		Password: cfg.Password,
		DB:       cfg.DB,
	})

	// 测试连接
	ctx := context.Background()
	_, err := redisClient.Ping(ctx).Result()
	return err
}

func pushToRedis(queueName string, message string) error {

	ctx := context.Background()
	// 使用前缀
	key := GlobalConfig.Redis.GetKey(queueName)
	return redisClient.RPush(ctx, key, message).Err()

}
